package 每日一题;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenhong
 * @version 1.0.0
 * @ClassName L1487.java
 * @createTime 2023年03月03日 10:07:00
 */
public class L1487 {
    public static void main(String[] args) {
        Solution1487 solution1487 = new Solution1487();
        solution1487.getFolderNames(new String[]{"kaido","kaido(1)","kaido","kaido(1)","kaido(2)"});
    }
}
class Solution1487 {
    public String[] getFolderNames(String[] names) {
        Map<String,Integer> map = new HashMap<>();

        for (int i = 0; i < names.length; i++) {
            if(map.containsKey(names[i])){
                Integer count = map.get(names[i]) + 1;
                StringBuffer name = new StringBuffer();
                name.append(names[i]);
                while (true){
                    name.append('(');
                    name.append(count);
                    name.append(')');
                    if(map.containsKey(name.toString())){
                        name.delete(names[i].length(),name.length());
                        count++;
                        continue;
                    }
                    map.put(names[i],count);
                    names[i] = name.toString();
                    map.put(name.toString(),0);
                    break;
                }
            }else {
                map.put(names[i],0);
            }
        }
        return names;
    }
}